package com.example.leetdemo.finash;

import java.util.ArrayList;
import java.util.List;

public class Solution1260 {

    public List<List<Integer>> shiftGrid(int[][] grid, int k) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> source = new ArrayList<>();
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                source.add(grid[i][j]);
            }
        }
        List<Integer> temp = new ArrayList<>();
        int n = grid.length * grid[0].length;
        if (k > n) {
            k = k % n;
        }
        temp.addAll(source.subList(n - k, n));
        temp.addAll(source);
        for (int i = 0; i < grid.length; i++) {
            list.add(temp.subList(grid[i].length * i, grid[i].length * (i + 1)));
        }
        return list;
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        System.err.println(list.subList(2, 3).size());
        System.err.println(list.size());
    }
}
